// +-------------------------------- DISCLAIMER ---------------------------------+
// |                                                                             |
// | This application program is provided to you free of charge as an example.   |
// | Despite the considerable efforts of Euresys personnel to create a usable    |
// | example, you should not assume that this program is error-free or suitable  |
// | for any purpose whatsoever.                                                 |
// |                                                                             |
// | EURESYS does not give any representation, warranty or undertaking that this |
// | program is free of any defect or error or suitable for any purpose. EURESYS |
// | shall not be liable, in contract, in torts or otherwise, for any damages,   |
// | loss, costs, expenses or other claims for compensation, including those     |
// | asserted by third parties, arising out of or in connection with the use of  |
// | this program.                                                               |
// +-----------------------------------------------------------------------------+
#include <iostream>
#include "ProcessingHandler.h"

#include <Easy.h>
using namespace Euresys::Open_eVision;

#include "CameraHandler.h"

int main()
{
  int error = 0;

  CameraHandler cameraHandler;
  ProcessingHandler processingHandler(&cameraHandler);  // defined after cameraHandler because
  // destructor must be called before cameraHandler

  processingHandler.start();
  cameraHandler.launchCamera();

  if (cameraHandler.isAborted() || processingHandler.isAborted())
  {
    std::cerr << "some error occured, closing application" << std::endl;
    error = -1;
  }
  else
  {
    std::this_thread::sleep_for(std::chrono::milliseconds(100));  // waits for 100ms, assuming a problem will have happened by then
    if (!processingHandler.isAborted() && !cameraHandler.isAborted())
    {
      std::cout << "Press anything to Quit\n" << std::endl;

      char c;
      std::cin >> c;
    }
    else
    {
      std::cerr << "An error occured, exciting" << std::endl;
    }
  }


  processingHandler.stop();
  cameraHandler.stop();

  return error;
}
